package linked;


/**
 * @author lakersUp
 * @Classname
 * @Description
 * @Date 2022/5/22 21:51
 * @Version 1.0
 */
public class AddTwoNumbers2 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode dummynode = new ListNode(-1),pre = dummynode;
        int t=0;
        while(l1!=null || l2!=null || t!=0){
            if(l1!=null){
                t+=l1.val;
                l1=l1.next;
            }
            if(l2!=null){
                t+=l2.val;
                l2=l2.next;
            }
            pre.next=new ListNode(t%10);
            pre=pre.next;
            t=t/10;
        }
        return dummynode;
    }
}
